package daily.play1;

import javax.imageio.plugins.tiff.TIFFImageReadParam;
import javax.lang.model.element.NestingKind;
import java.io.*;
import java.net.SocketTimeoutException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.spi.TimeZoneNameProvider;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

//class Student implements Serializable{
//    private static final long serialVersionUID = 4112130861713642419L;
//    String name;
//    static int age;
//    String sex;
//
//    public Student(String name, int age) {
//        this.name = name;
//        this.age = age;
//    }
//
//    @Override
//    public String toString() {
//        return "Student{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                ", sex='" + sex + '\'' +
//                '}';
//    }
//}
//public class demo14 {
//    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\java-code\\daily-java\\src\\\\daily\\play1\\copy.txt"));
//
//        oos.writeObject(new Student("liu",22));
//
//        oos.close();
//    }
//}

//class Student implements Serializable {
//    private static final long serialVersionUID = 2393419151226372460L;
//    String name;
//    int age;
//
//    public Student(String name, int age) {
//        this.name = name;
//        this.age = age;
//    }
//    @Override
//    public String toString() {
//        return "Student{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                '}';
//    }
//}
//public class demo14{
//    public static void main(String[] arsg) throws IOException {
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src\\daily\\play1\\copy.txt"));
//        ArrayList<Student> list = new ArrayList<>();
//        list.add(new Student("zhangsan",23));
//        list.add(new Student("lisi",24));
//        list.add(new Student("zhaowu",25));
//        oos.writeObject(list);
//        oos.close();
//    }
//}

/*public class demo14{
    public static void main(String[] arga) throws FileNotFoundException {
        PrintStream ps = new PrintStream(new FileOutputStream("src\\daily\\play1\\copy.txt"),true,Charset.forName("UTF-8"));
        ps.println("nihao");
        ps.print(666);
        ps.printf("hello world %s","good");
        ps.printf("hello world %s","good");
        ps.close();
    }
}*/

/*public class demo14{
    public static void main(String[] args) throws IOException {
       PrintWriter pw = new PrintWriter(new FileWriter("src\\daily\\play1\\copy.txt"));
       pw.println("你好世界");
       System.out
//       pw.close();
    }
}*/

//public class demo14{
//    public static void main(String[] arga) throws IOException {
//        File file = new File("C:\\Users\\liulo\\Desktop\\官方文件.zip");
//        File dest = new File("C:\\Users\\liulo\\Desktop");
//        unzip(file,dest);
//
//    }
//    public static void unzip(File file,File dest) throws IOException {
//        ZipInputStream zip = new ZipInputStream(new FileInputStream(file));
//        ZipEntry entry;
//        while((entry=zip.getNextEntry())!=null){
//            if(entry.isDirectory()){
//                //文件夹的处理方案
//                File timefilr = new File(dest,entry.toString());
//                timefilr.mkdirs();
//            }else {
//                //文件的处理方案
//                FileOutputStream fos = new FileOutputStream(new File(dest,entry.toString()));
//                int n;
//                while((n = zip.read())!=-1){
//                    fos.write(n);
//                }
//                fos.close();
//                zip.closeEntry();
//            }
//
//        }
//        zip.close();
//    }
//}


//public class demo14{
//    public static void main(String[] arg) throws IOException {
//        File file = new File("C:\\Users\\liulo\\Desktop\\练习1.txt");
//        File dest = new File("C:\\Users\\liulo\\Desktop");
//        toZip( file, dest);
//    }
//    public static void toZip(File file, File dest) throws IOException {
//        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(dest,"a.zip")));
//        ZipEntry ze = new ZipEntry("a.txt");
//        zos.putNextEntry(ze);
//        FileInputStream fis = new FileInputStream(file);
//        int n;
//        while((n = fis.read())!=-1){
//            zos.write(n);
//        }
//        fis.close();
//        zos.close();
//    }
//}

//
//public class demo14{
//    public  static void main(String[] args) throws IOException {
//        File file = new File("C:\\Users\\liulo\\Desktop\\官方文件");
//        File dest = new File("C:\\Users\\liulo\\Desktop");
//        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(dest,file.getName()+".zip")));
//        toZip(file,zos,file.getName());
//    }
//    public static void toZip(File file, ZipOutputStream zos, String name) throws IOException {
//        File [] files = file.listFiles();
//        if(files!=null){
//            for(File f : files){
//                if(f.isDirectory()){
//                    toZip(f,zos,name+"/"+f.getName());
//                }else{
//                    ZipEntry entry = new ZipEntry(name+"/"+f.getName());
//                    zos.putNextEntry(entry);
//                    FileInputStream fis = new FileInputStream(f);
//                    int n;
//                    while ((n = fis.read())!=-1){
//                        zos.write(n);
//                    }
//                    fis.close();
//                    zos.closeEntry();
//                }
//            }
//        }
//    }
//}

//多线程
//class MyThread extends Thread{
//    public void run(){
//        for (int i = 0; i < 100; i++) {
//            System.out.println(getName()+"hello world");
//        }
//
//    }
//}
//
//public class demo14{
//    public static void main(String[] args){
//        MyThread t1 = new MyThread();
//        t1.setName("线程1");
//        MyThread t2 = new MyThread();
//        t2.setName("线程2");
//        t1.start();
//        t2.start();
//
//    }
//}

//class MyThread implements Runnable{
//
//    @Override
//    public void run() {
//        for (int i = 0; i < 100; i++) {
//            System.out.println(Thread.currentThread().getName()+"hello world");
//        }
//    }
//}
//public class demo14{
//    public static void main(String[] args){
//        MyThread t1 = new MyThread();
//        MyThread t2 = new MyThread();
//        Thread t = new Thread(t1);
//        t.setName("线程1");
//        Thread t3 = new Thread(t2);
//        t3.setName("线程2");
//        t.start();
//        t3.start();
//    }
//}
//
//public class demo14{
//    public static void main(String[] args) {
//        Thread t = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("nihao");
//            }
//        });
//        t.start();
//    }
//}
class Mytest implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        int sum=0;
        for (int i = 1; i <= 100; i++) {
            sum+=i;
        }
        return sum;
    }
}
public class demo14{
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Mytest test = new Mytest();
        FutureTask<Integer> future  = new FutureTask<>(test);
        Thread thread = new Thread(future);
        thread.start();
        System.out.println(future.get().intValue());
    }
}